define(['jquery', 'bootstrap', 'backend', 'table', 'form','zoomify.min'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'extension/goods/index' + location.search,
                    add_url: 'extension/goods/add',
                    sync_url:'extension/goods/enter',
                    // edit_url: 'goods/goods/edit',
                    del_url: 'extension/goods/del',
                    multi_url: 'extension/goods/multi',
                    import_url: 'extension/goods/import',
                    table: 'extension',
                }
            });

            var table = $("#table");
            Fast.config.openArea = ['60%','70%'];
            // //在普通搜索渲染后
            table.on('post-common-search.bs.table', function (event, table) {
                var form = $("form", table.$commonsearch);
                $("input[name='invite']", form).addClass("selectpage").data("source", "general/staff/index").data("primaryKey", "invite").data("field", "invite").data("orderBy", "id desc");
                Form.events.cxselect(form);
                Form.events.selectpage(form);
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'staff.name', title: __('员工'), operate: 'LIKE'},
                        {field: 'invite', title: __('邀请码'), operate: false},
                        {field: 'goods_sn', title: __('商品编号'), operate: 'LIKE'},
                        {field: 'price', title: __('价格'), operate: false},
                        {field: 'status', title: __('状态'),searchList: {"1":"上架","2":"下架","3":"审核失败","4":"审核中","5":"平台下架"}, formatter: Table.api.formatter.flag},
                        {field: 'gamename', title: __('游戏区服'), operate: 'LIKE',
                            formatter:function(value,row,index){
                                var html = value+'/';
                                if(row.plat != null){
                                    html += row.plat+'/';
                                }
                                if(row.operator != null){
                                    html += row.operator+'/';
                                }
                                if(row.area != null){
                                    html += row.area+'/';
                                }
                                if(row.server != null){
                                    html += row.server;
                                }
                                return html;
                            }
                        },
                        {field: 'type_name', title: __('商品类型'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'havetime', title: __('有效期'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                // {
                                //     name: 'opra',
                                //     text: __(''),
                                //     title: __('审核'),
                                //     classname: 'btn btn-xs btn-info btn-dialog',
                                //     icon: 'fa fa-pencil',
                                //     url: 'extension/goods/edit',
                                //
                                // },
                                {
                                    name: 'info',
                                    text: __(''),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-eye',
                                    url: 'extension/goods/info',

                                },
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        examine: function () {
            Controller.api.bindevent();
        },
        info: function () {
            Controller.api.bindevent();
        },
        opra: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                $(".item").LightBox({
                    controls : true          //上一张、下一张按钮是否显示，默认是显示true
                });
                $(document).on('click', "input[name='row[type]']", function () {
                    var name = $("input[name='row[type]']");
                    var ismenu = $(this).val() == 1;
                    name.prop("placeholder", ismenu ? name.data("placeholder-menu") : name.data("placeholder-node"));
                    $('div[data-type="menu"]').toggleClass("hidden", !ismenu);
                    $('div[data-type="menu-image"]').toggleClass("hidden", ismenu);
                });
                $("input[name='row[type]']:checked").trigger("click");
            }
        }


    };
    return Controller;
});
